<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
</head>

<body>
    <div class="nav">
        五子棋对战
      </div>
        <div class="login-container">
            <!-- 登陆界面的对话框 -->
             <div class="login-dialog">
                <!-- 提示信息 -->
                 <h3>注册</h3>
                 <!-- 这个表示一行 -->
                  <div class="row">
                    <span>用户名</span>
                    <input type="text" id="username">
                    </div>
                    <!-- 这里表示另一行 -->
                     <div class="row">
                        <span>密码</span>
                        <input type="password" id="password">
                     </div>
                     <!-- 提交按钮 -->
                      <div class="row">
                        <button id="submit">提交</button>
                      </div>
                  </div>
             </div>
        </div>

        <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
        <script>
            let submitButton = document.querySelector("#submit");

            submitButton.onclick = function(){
                let username = document.querySelector('#username').value;
                let password = document.querySelector('#password').value;
                $.ajax({
                    type: "post",
                    url: "/userController/register",
                    data: {
                        username: username,
                        password: password
                    },
                    //若请求成功则会返回一个user对象
                    success:function(data){
                        if (data.username) {
                            alert("注册成功！");
                            location.href = "/gobang_login.html";
                        } else {
                            alert("注册失败")
                        }
                    },
                    error:function(){
                        alert("注册失败！")
                    }
                });
            }
        </script>
</body>
</html>